package com.fanrenqiji.modules.sys.dao;

import com.fanrenqiji.common.persistence.BaseDao;
import com.fanrenqiji.common.persistence.BaseDaoImpl;
import com.fanrenqiji.modules.sys.entity.Area;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author lijian E-mail:ljz0721cx@163.com
 * @version 创建时间：2015年1月26日 下午3:07:36
 * @description
 */
public interface AreaDao extends AreaDaoCustom, CrudRepository<Area, Long> {
	@Modifying
	@Query("update Area set delFlag='" + Area.DEL_FLAG_DELETE + "' where id = ?1 or parentIds like ?2")
	public int deleteById(Long id, String likeParentIds);
	
	public List<Area> findByParentIdsLike(String parentIds);

	@Query("from Area where delFlag='" + Area.DEL_FLAG_NORMAL + "' order by code")
	public List<Area> findAllList();
	
	@Query("from Area where (id=?1 or parent.id=?1 or parentIds like ?2) and delFlag='" + Area.DEL_FLAG_NORMAL + "' order by code")
	public List<Area> findAllChild(Long parentId, String likeParentIds);
	
	@Query("select code from Area where delFlag='" + Area.DEL_FLAG_NORMAL + "' and code = ?1")
	public List<String> findAreaByCode(String code);
	
	@Query("select id,name from Area where delFlag='" + Area.DEL_FLAG_NORMAL + "' and parent.id = ?1")
	public List<Area> findAreaByParentId(Long parentId);

}


interface AreaDaoCustom extends BaseDao<Area>{
}

@Repository
class AreaDaoImpl extends BaseDaoImpl<Area> implements AreaDaoCustom{
	
}